<?php
final class JsonSafe
{
    static function json_encode($str)
    {
        return json_encode(self::json_fix_cyr($str));
    }
    
    private function json_fix_cyr($var)
    {
       if (is_array($var)) {
           $new = array();
           foreach ($var as $k => $v) {
               $new[self::json_fix_cyr($k)] = self::json_fix_cyr($v);
           }
           $var = $new;
       } elseif (is_object($var)) {
           $vars = get_object_vars($var);
           foreach ($vars as $m => $v) {
               $var->$m = self::json_fix_cyr($v);
           }
       } elseif (is_string($var)) {
           $var = iconv('cp1251', 'utf-8', $var);
       }
       return $var;
    }

    
    
}
?>